﻿Imports System.Data.SqlClient
Imports System.Data.Odbc
Imports System.Data.OleDb


Module Rutinas
    Friend Function BuscarStrDatoContabilidad(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoContabilidad(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoContabilidad(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoContabilidad(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoContabilidad(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoContabilidad(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoContabilidad(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoContabilidad(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlContabilidad(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try
            cnnConn.ConnectionString = ContabilidadConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
    Friend Function BuscarStrDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoNominas(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoNominas(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoNominas(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoNominas(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlNominas(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = NominasConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
   
    Friend Function BuscarStrDatoOptoControl(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoOptoControl(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Friend Function BuscarGuidDatoOptoControl2(ByVal strSqlQry As String) As String
        Dim cnConn As New SqlConnection
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader
        Dim strRetVal As String

        Dim g As Guid

        Try
            cnConn.ConnectionString = OptocontrolConnection
            cmdBuscar.Connection = cnConn
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry

            cnConn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Do While rdBuscar.Read()
                g = rdBuscar("ID_VEHICULO")
                strRetVal = g.ToString
                Exit Do
            Loop

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try

        'If strRetVal Is Nothing Then
        'Return ""
        'Else
        Return strRetVal
        'End If

    End Function

    Friend Function BuscarDateDatoOptoControl(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoOptoControl(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoOptoControl(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoOptoControl(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            'dblRetVal = cmdBuscar.ExecuteScalar

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                dblRetVal = cmdBuscar.ExecuteScalar
            Else
                dblRetVal = 0
            End If

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoOptoControl(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoOptoControl(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlOptoControl(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = OptocontrolConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function

    Friend Function BuscarStrDatoAUSL(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoAUSL(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoAUSL(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoAUSL(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoAUSL(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally

            'Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoAUSL(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Double

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoAUSL(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoAUSL(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlAUSL(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = AUSLConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
    Friend Function BuscarStrDatoInicialContabilidad(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Server=" & Server & "\COMPAC" & ";database=GeneralesSQL;user id = SA; password = Compac123;"
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoInicialContabilidad(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Server=" & Server & "\COMPAC" & ";database=GeneralesSQL;user id = SA; password = Compac123;"
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Friend Function BuscarStrDatoInicialNominas(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Server=" & Server & "\COMPAC" & ";database=nomGenerales;user id = SA; password = Compac123;"
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoInicialNominas(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Server=" & Server & "\COMPAC" & ";database=nomGenerales;user id = SA; password = Compac123;"
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Friend Function BuscarStrDatoInicialAdminPAQ(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Driver={Microsoft Visual FoxPro Driver};sourcedb=\\" & Server & "\CONTPAQ\CompacW\Empresas;sourcetype=DBF;exclusive=No;"
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoInicialAdminPAQ(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Driver={Microsoft Visual FoxPro Driver};sourcedb=\\" & Server & "\CONTPAQ\CompacW\Empresas;sourcetype=DBF;exclusive=No;"
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Friend Function BuscarStrDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoInicial(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoInicial(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoInicial(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoInicial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoInicial(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlInicial(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = InitialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
    Friend Function BuscarIntDatoBiometria(ByVal strSqlQry As String) As String
        Dim cnnConn As New OleDbConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CitraInicial & "\UFDatabase.mdb;"
            cnnConn.Open()

            Dim cmdBuscar As New OleDbCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarStrDatoBiometria(ByVal strSqlQry As String) As String
        Dim cnnConn As New OleDbConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CitraInicial & "\UFDatabase.mdb;"
            cnnConn.Open()

            Dim cmdBuscar As New OleDbCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
    Friend Function BuscarIntDatoBiometriaOperadores(ByVal strSqlQry As String) As String
        Dim cnnConn As New OleDbConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = BiometriaConnectionOperadores
            cnnConn.Open()

            Dim cmdBuscar As New OleDbCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarStrDatoBiometriaOperadores(ByVal strSqlQry As String) As String
        Dim cnnConn As New OleDbConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = BiometriaConnectionOperadores
            cnnConn.Open()

            Dim cmdBuscar As New OleDbCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OleDbException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarIntDatoAdminPAQAnterior(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = AdminPAQAnteriorConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoAdminPAQAnterior(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = AdminPAQAnteriorConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarStrDatoAdminPAQAnterior(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = AdminPAQAnteriorConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoAdminPAQAnterior(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = AdminPAQAnteriorConnection
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function DiaTrabajado(ByVal Fecha As Date) As Boolean

        Dim IdDia As Integer = BuscarIntDatoCitra("SELECT IdDia FROM DiaTrabajadoLiquidacion Where Dia=" & Fecha.Day & " AND Mes=" & Fecha.Month & " AND Anio=" & Fecha.Year)

        If IdDia > 0 Then
            DiaTrabajado = True
        Else
            DiaTrabajado = False
        End If

    End Function
    Friend Function DiaTrabajadoDiesel(ByVal Fecha As Date) As Boolean

        Dim IdDia As Integer = BuscarIntDatoCitra("SELECT IdDia FROM DiaTrabajadoDiesel Where Dia=" & Fecha.Day & " AND Mes=" & Fecha.Month & " AND Anio=" & Fecha.Year)

        If IdDia > 0 Then
            DiaTrabajadoDiesel = True
        Else
            DiaTrabajadoDiesel = False
        End If

    End Function
    Friend Function DiaTrabajadoPagobus(ByVal Fecha As Date) As Boolean

        Dim IdDia As Integer = BuscarIntDatoCitra("SELECT IdDia FROM DiaTrabajadoPagobus Where Dia=" & Fecha.Day & " AND Mes=" & Fecha.Month & " AND Anio=" & Fecha.Year)

        If IdDia > 0 Then
            DiaTrabajadoPagobus = True
        Else
            DiaTrabajadoPagobus = False
        End If

    End Function
    Sub ToExcel(ByVal Grid As DataGridView, ByVal Titulo As String)
        Dim xl As Object
        Dim wb As Object
        Dim i As Integer
        Dim j As Integer
        Dim intRenglones As Integer
        Dim intColumnas As Integer
        xl = CreateObject("Excel.Application")
        xl.Visible = True
        xl.Workbooks.Add() ' (Template:=RutaPlantilla & "UTNA_Cotizacion.xlt")
        wb = xl.activeworkbook
        intRenglones = Grid.Rows.Count
        intColumnas = Grid.ColumnCount
        Dim rng As Integer
        rng = 6
        wb.SHEETS(1).cells(1, 1).value = "Imprimiendo..."
        wb.SHEETS(1).columns(1).columnwidth = 15
        For i = 1 To intRenglones
            For j = 1 To intColumnas
                wb.SHEETS(1).cells(rng, j).value = Grid.Rows(i - 1).Cells(j - 1).Value
                wb.SHEETS(1).cells(rng, j).font.size = 10
            Next
            rng = rng + 1
        Next
        ' Formatear

        wb.SHEETS(1).cells(1, 1).value = EmpresaActiva
        wb.SHEETS(1).cells(1, 1).FONT.SIZE = 14
        wb.SHEETS(1).cells(2, 1).value = Titulo
        wb.SHEETS(1).cells(2, 1).FONT.SIZE = 10
        wb.SHEETS(1).cells(3, 1).value = "Impreso por: " & usuarioactivo & " el " & Now().Day & "-" & Now().Month & "-" & Now().Year
        wb.SHEETS(1).cells(3, 1).FONT.SIZE = 8

        For j = 1 To intColumnas
            wb.SHEETS(1).cells(5, j).value = Grid.Columns(j - 1).HeaderText
            ' wb.SHEETS(1).cells(3, j).font.size = 6
            wb.SHEETS(1).cells(5, j).font.bold = -1 ' TRUE
            wb.SHEETS(1).columns(j).columnwidth = Grid.Columns(j - 1).Width / 8 ' 9
            'Columns("G:G").ColumnWidth = 6.14
        Next


        'MsgBox("Reporte generado", MsgBoxStyle.Information)
    End Sub
    Friend Function TienePermiso(ByVal Formulario As String) As String
        Dim idUser As Integer = BuscarIntDatoInicial("Usuarios", "IdUsuario", "Nombre='" & UCase(UsuarioActivo.Trim) & "'")
        Dim idFormulario As String = BuscarIntDatoInicial("Formularios", "IdFormulario", "formulario='" & Formulario.Trim & "'")
        Dim Permiso As Integer = BuscarIntDatoInicial("PermisosUsuarios", "Permiso", "IdUsuario=" & idUser & " AND IdFormulario=" & idFormulario)
        Dim Acceso As Boolean
        If Permiso > 0 Then
            Acceso = True
        Else
            Acceso = False
        End If

        Return Acceso
    End Function
    Function fDespliegaCatalogosF3(ByVal aTipoCatalogo As Integer) As String
        TextoConsulta = ""
        TextoConsulta2 = ""


        Select Case aTipoCatalogo
            Case 1 ' Clientes
                ' Titulo de la ventana de acuerdo al catálogo seleccionado
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Autobuses"
                TextoConsulta = "Select cidclien01 as Codigo, ccodigoc01,crazonso01 as Nombre from mgw10002 where ctipocli01=1 and cestatus=1 "
                TextoConsulta2 = "Select cidclien01 as Codigo,ccodigoc01, crazonso01 as Nombre from mgw10002 where ctipocli01=1  and cestatus=1 and crazonso01"


            Case 2 ' Proveedores
                ' Titulo de la ventana de acuerdo al catálogo seleccionado
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Servicios"
                TextoConsulta = "Select NumServici as Codigo,Descripcio as Nombre From servicios"
                TextoConsulta2 = "Select NumServici as Codigo,Descripcio as Nombre From servicios where descripcio"

            Case 3 ' Productos
                ' Titulo de la ventana de acuerdo al catálogo seleccionado
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Productos"
                TextoConsulta = "Select ccodigop01 as Codigo, cnombrep01 as Nombre from mgw10005 "
                TextoConsulta2 = "Select ccodigop01 as Codigo, cnombrep01 as Nombre from mgw10005 where cnombrep01"

            Case 4 ' Agentes
                ' Titulo de la ventana de acuerdo al catálogo seleccionado
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Operadores"
                TextoConsulta = "Select cidAgente as Codigo, ccodigoa01 as ccodigoc01, cnombrea01 as Nombre  from mgw10001 where cnombrea01<>'E' and cnombrea01 <>'B' and ccodigoa01<>'(Ninguno)                     '"
                TextoConsulta2 = "Select cidAgente as Codigo, ccodigoa01 as ccodigoc01,cnombrea01 as Nombre  from mgw10001 where cnombrea01<>'E' and cnombrea01 <>'B' and ccodigoa01<>'(Ninguno)                     ' and cnombrea01"

            Case 5 ' Almacenes
                ' Titulo de la ventana de acuerdo al catálogo seleccionado
                EsAlmacen = True
                frmCatalogos.Text = "Catalogo de Almacenes"
                TextoConsulta = "Select ccodigoa01 as Codigo, cnombrea01 as Nombre  from mgw10003"
                TextoConsulta2 = "Select ccodigoa01 as Codigo, cnombrea01 as Nombre  from mgw10003 where cnombrea01"

            Case 6 ' Monedas
                ' Titulo de la ventana de acuerdo al catálogo seleccionado
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Personal"
                TextoConsulta = "Select id as Codigo, nombre as Nombre  from personal where status<>'Baja'"
                TextoConsulta2 = "Select id as Codigo, nombre as Nombre  from personal where status<>'Baja' and nombre"

            Case 7 'Conceptos
                EsAlmacen = False
                frmCatalogos.Text = "Conceptos de Captura"
                TextoConsulta = "Select ccodigoc01 as Codigo, cnombrec01 as Nombre  from mgw10006"
                TextoConsulta2 = "Select ccodigoc01 as Codigo, cnombrec01 as Nombre  from mgw10006 where cnombrec01"

            Case 8 'Codigos
                EsAlmacen = False
                frmCatalogos.Text = "Conceptos de Captura"
                TextoConsulta = "Select cidconce01 as Codigo, cnombrec01 as Nombre  from mgw10006"
                TextoConsulta2 = "Select cidconce01 as Codigo, cnombrec01 as Nombre  from mgw10006 where cnombrec01"

            Case 9 'SubServicios
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Sub-Servicios"
                TextoConsulta = "Select id as Codigo, nombre as Nombre  from subservicios"
                TextoConsulta2 = "Select id as Codigo, nombre as Nombre  from subservicios where nombre"

            Case 10 'Rutas
                EsAlmacen = False
                frmCatalogos.Text = "Catalogo de Rutas"
                TextoConsulta = "Select id as Codigo, ruta as Nombre  from rutas"
                TextoConsulta2 = "Select id as Codigo, ruta as Nombre  from rutas where ruta"
        End Select

        frmCatalogos.ShowDialog()
        If frmCatalogos.DialogResult = Windows.Forms.DialogResult.OK Then
            strResult = frmCatalogos.Valor
        End If
        Return aTipoCatalogo

    End Function
    Friend Function SetSqlAdminPAQ(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = AdminPAQConnection1
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As OdbcException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function

    Sub ImportaTablas(ByVal Tipo As Integer)
        Call SetSqlCitra("UPDATE EstadoImportacion Set TipoImportacion=" & Tipo & ", Resultado=1 WHERE IdImportacion=1")
    End Sub
    Friend Function BuscarStrDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoCitra(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoCitra(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally

            'Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoCitra(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Double

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Dispose()
                cnnConn.Close()
                SqlConnection.ClearAllPools()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoCitra(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoCitra(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            If Not IsDBNull(cmdBuscar.ExecuteScalar) Then
                intRetVal = cmdBuscar.ExecuteScalar
            Else
                intRetVal = 0
            End If


        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally

            'Finally
            'If cnnConn.State = ConnectionState.Open Then
            'cnnConn.Close()
            'End If
        End Try

        cnnConn.Close()
        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function SetSqlCitra(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try

            cnnConn.ConnectionString = CitraConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
    Friend Function BuscarStrDatoComercial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = AdminPAQConnection1
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarStrDatoComercial(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = AdminPAQConnection1
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function

    Friend Function BuscarDateDatoComercial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Date

        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = ComercialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            ' CAMBIO: 13.11.07 ISNULL NO USADO EN VFP            cmdBuscar.CommandText = "Select IsNull(" & strCampo & ", '01/01/1900') From " & strTabla & " Where " & strWhere
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDateDatoComercial(ByVal strSqlQry As String) As Date
        Dim cnnConn As New SqlConnection
        Dim dRetVal As Date

        Try

            cnnConn.ConnectionString = ComercialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return dRetVal

    End Function

    Friend Function BuscarDblDatoComercial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = ComercialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Catch ex As Exception
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarDblDatoComercial(ByVal strSqlQry As String) As Double
        Dim cnnConn As New SqlConnection
        Dim dblRetVal As Double

        Try

            cnnConn.ConnectionString = ComercialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            dblRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If dblRetVal = Nothing Then
            Return 0
        Else
            Return dblRetVal
        End If

    End Function

    Friend Function BuscarIntDatoComercial(ByVal strTabla As String, ByVal strCampo As String, ByVal strWhere As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = ComercialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = "Select " & strCampo & " From " & strTabla & " Where " & strWhere
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function

    Friend Function BuscarIntDatoComercial(ByVal strSqlQry As String) As String
        Dim cnnConn As New OdbcConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = AdminPAQConnection1
            cnnConn.Open()

            Dim cmdBuscar As New OdbcCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function
    Friend Function BuscarIntDatoComercialInicial(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim intRetVal As Integer

        Try
            cnnConn.ConnectionString = ComercialConnectionInicial
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            intRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)

        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If intRetVal = Nothing Then
            Return 0
        Else
            Return intRetVal
        End If

    End Function


    Friend Function SetSqlComercial(ByVal strSqlQry As String) As Boolean
        Dim cnnConn As New SqlConnection
        Dim intRetVal As String
        Dim blnRetVal As Boolean

        Try
            cnnConn.ConnectionString = ComercialConnection
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn
            cmdBuscar.CommandTimeout = 0

            intRetVal = cmdBuscar.ExecuteNonQuery

            blnRetVal = True

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        Return blnRetVal

    End Function
    Friend Function BuscarStrDatoComercialInicial(ByVal strSqlQry As String) As String
        Dim cnnConn As New SqlConnection
        Dim strRetVal As String = ""

        Try

            cnnConn.ConnectionString = ComercialConnectionInicial
            cnnConn.Open()

            Dim cmdBuscar As New SqlCommand
            cmdBuscar.CommandTimeout = 0
            cmdBuscar.CommandText = strSqlQry
            cmdBuscar.Connection = cnnConn

            strRetVal = cmdBuscar.ExecuteScalar

        Catch ex As SqlException
            MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            If cnnConn.State = ConnectionState.Open Then
                cnnConn.Close()
            End If
        End Try

        If strRetVal Is Nothing Then
            Return ""
        Else
            Return strRetVal.Trim
        End If

    End Function
End Module
